package com.vip.mvc.demo.service;

import com.vip.mvc.akka.Promises;
import com.vip.mvc.annotation.Service;
import com.vip.mvc.demo.msg.DemoReq;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import scala.concurrent.Future;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by cloudy.xie on 17/2/21.
 */
@Service
public class DemoService {
    private Logger logger = LoggerFactory.getLogger(DemoService.class);

    public Future<Object> testService(DemoReq demoReq){
        logger.info("service thread ="+Thread.currentThread().getName());
        return Promises.flatMap(demoReq, req -> {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            Map<String, String> returnMap = new HashMap<>();
            returnMap.put("async", "async ++++++++++++++");
            returnMap.put("one", "testONe");
            returnMap.put("two", "testONe2");
            returnMap.put("one2", "testONe3");
            returnMap.put("id", String.valueOf(req.getId()));
            returnMap.put("name", req.getName());


            logger.info("service22222 thread ="+Thread.currentThread().getName());
            return returnMap;
        });
    }
}
